package hu.myai.calculators;

import hu.myai.model.db.AxHistory;
import hu.myai.model.graph.FibNode;
import hu.myai.model.sp.StockPivot;

import java.util.List;

public class FibonacciFanMax extends AbstractFibonacciFan {

	public FibonacciFanMax(String symbol, StockPivot maxStock, StockPivot minStock, List<AxHistory> stockList,
			List<StockPivot> stockPivotList) {
		super(symbol, maxStock, minStock, stockList, stockPivotList);
	}

	/**
	 * set the fibonacci fan levels for all stock pivot after the season turning
	 * point. The next max / min is set to 50% fibo fan value<br>
	 * 
	 * @param mode
	 *            void
	 * @return status<br>
	 *         0 - error<br>
	 *         1 - possible to step forward<br>
	 *         -1 - out of range, please step backwards
	 */
	@Override
	public int calculator(int mode) {

		referenceStock = maxStock;

		int numOfTouch = 0;
		int nullPivotIndex = stockPivotList.indexOf(referenceStock) + 1;

		if (nullPivotIndex >= stockPivotList.size())
			return -1;

		// set next max pivot to 50% fibo fan distance
		StockPivot nullPivot = stockPivotList.get(nullPivotIndex);
		numOfTouch = setFibFanNodeValues(referenceStock, nullPivot);

		// result is out of interval
		if (getLastFibFanNode().getFibLevel() == 0.0 || getLastFibFanNode().getFibLevel() >= 1.0)
			return 0;

		return numOfTouch;
	}

	protected FibNode getFibFanNode(StockPivot stockPivot) {
		return stockPivot.getFibMaxFanNode();
	}

	protected double getPercentFromFanSupport(StockPivot stockPivot) {
		return stockPivot.getPercentFromFanMaxSupport();
	}

	protected double getTangensAlpha(StockPivot stockPivot) {
		return stockPivot.getTangensAlphafromMax();
	}

	protected void setFibFanNode(StockPivot stockPivot, FibNode fibMaxFanNode) {
		stockPivot.setFibMaxFanNode(fibMaxFanNode);
	}

	protected void setPercentFromFanSupport(StockPivot stockPivot, double percentFromFanMaxSupport) {
		stockPivot.setPercentFromFanMaxSupport(percentFromFanMaxSupport);
	}

	protected void setTangensAlpha(StockPivot stockPivot, double tangensAlphafromMax) {
		stockPivot.setTangensAlphafromMax(tangensAlphafromMax);
	}

}
